package org.example.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.dto.RoomData;
import org.example.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;


/**
 * 对于房间的操作Controller
 *
 * @Author 刘新
 * @Date 2023/10/30 16:03
 */
@Api(tags = "放假")
@RestController
@RequestMapping("/room")
public class RoomController {

    @Autowired
    private RoomService roomService;

    /**
     * 加入房间
     *
     * @return
     */
    @ApiOperation(value = "加入房间", notes = "加入房间")
    @PostMapping("joinRoom")
    public String joinRoom(@NotNull @RequestParam("userId") Long userId, @NotNull @RequestParam("roomId") Long roomId) {
        return roomService.joinRoom(userId, roomId);
    }


    /**
     * 退出房间
     *
     * @return
     */
    @ApiOperation(value = "退出房间", notes = "退出房间")
    @PostMapping("quitRoom")
    public String quitRoom(@NotNull @RequestParam("userId") Long userId, @NotNull @RequestParam("roomId") Long roomId) {
        return roomService.quitRoom(userId, roomId);
    }


    /**
     * 更新房间对战数据
     *
     * @return
     */
    @ApiOperation(value = "房间对战数据", notes = "房间对战数据")
    @PostMapping("updateBattleDataByRoom")
    public String updateBattleDataByRoom(@RequestBody RoomData roomData) {
        return roomService.updateBattleDataByRoom(roomData);
    }

    /**
     * 获取房间数据
     *
     * @return
     */
    @ApiOperation(value = "房间对战数据", notes = "房间对战数据")
    @PostMapping("getRoomData")
    public RoomData getRoomData(@NotNull @RequestParam("roomId") Long roomId) {
        return roomService.getRoomData(roomId);
    }
}
